<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', function () {
	session(['login'=>true]);
	// Config::get('app.timezone');
	// Config::set('key','val');

    return view('welcome');
});

// 路由的格式
Route::get('/test/{id}/{name}',function($id,$name){
	echo $id.'------'.$name;
});

// 参数 限定
Route::get('/user/edit/{id}/{name}-{age}',function($id,$name,$age){
	echo '修改的用户id：'.$id.'修改用户的name:'.$name.'年龄为:'.$age;
})->where('id','[0-9]+')->where('name','[a-zA-Z]+');


// 带别名的路由
Route::get('/admin/user/delete/{id}',['as'=>'aud',function($id){
	echo '删除的id：'.$id;
	echo '<br>';
	// 通过别名 获取url
	// echo route('aud',['id'=>1]);
	// 创建url
	// echo url('admin/user/edit');
}]);
// http 路由匹配失败
// NotFoundHttpException in RouteCollection.php line 161:  



// 路由组的设置 对一组路由进行统一管理的
Route::group(['middleware'=>'login'],function(){
	// 路由
	Route::get('/user/add',function(){
		echo '用户添加';
	});

	Route::get('/user/edit',function(){
		echo '用户修改';
	});
	Route::get('/user/delete',function(){
		echo '用户删除';
	});
});

// TokenMismatchException in VerifyCsrfToken.php line 53:	  scrf 验证失败
// post 路由
Route::post('/insert',function(){
	// var_dump($_POST);
	echo 'csrf';
});

Route::get('/form',function(){
	// 加载视图
	return view('form');
});

// 登录
Route::get('/login',function(){
	echo '登录页面';
});

// 中间件
// 作用：实现或者是执行各式各样的任务
/**
 * 步骤：
 * 	1. 创建中间件	php artisan make:middleware LoginMiddleware
 * 	2. 在中间件里面填写实例代码 	
 * 	3. 注册中间件      Kernel.php:  'login' => \App\Http\Middleware\LoginMiddleware::class,
 * 	4. 使用中间件 		 Route::group(['middleware'=>'login'],function(){});
 */

// 控制器
Route::get('/test/index/{id}','TestController@index');
Route::get('/test/edit','TestController@edit');
// 别名
Route::get('/test/delete',['as'=>'td','uses'=>'TestController@delete']);

// 隐式 控制器
Route::controller('/admin/article','ArticleController');

// 资源控制器
Route::resource('/admin/goods', 'GoodsController');